package cn.mumzone.pos.presenter;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.basic.util.PatternUtils;
import cn.mumzone.pos.model.MemberEntity;
import cn.mumzone.pos.model.source.MemberRepository;
import cn.mumzone.pos.presenter.contract.MemberContract;

/**
 * Created By Dlx
 * on 2019/7/3
 */
public class MemberPresenter extends AbsPresenter<MemberContract.View, MemberRepository> implements MemberContract.Presenter {
    @Override
    public void searchMember(String phone) {

        if (!PatternUtils.isMobileNO(phone)) {
            mView.showError("手机号格式不正确");
            return;
        }

        ApiCallBack<MemberEntity> callBack = new ApiCallBack<MemberEntity>() {
            @Override
            public void onSuccess(MemberEntity memberEntity) {
                mView.dismissLoadingDialog();
                mView.showSearchMemberSuccess(memberEntity);
            }

            @Override
            public void onError(BaseResponse response) {
                mView.dismissLoadingDialog();
                mView.showError(response.getMsg());
            }

            @Override
            public void onNetworkError(BaseResponse response) {
                mView.showNetError();
            }
        };
        mView.showLoadingDialog();
        mRepo.getMemberInfoByPhone(phone, callBack);
        addSubscrebe(callBack);

    }
}
